
import axios from 'axios'
/** El-config-provider 配置信息接口 */
export interface ConfigProvider {
    elsize: string
    button: {
        autoInsertSpace: boolean
    }
}
/** 全局Json配置接口 */
export interface JsonSetting {
    'el-config-provider': ConfigProvider
}
/** 默认全局配置值  */
export const defaultJsonSettings: JsonSetting = {
    'el-config-provider': {
        elsize: 'default',
        button: {
            autoInsertSpace: true
        }
    }
}

let settings: JsonSetting | null = null

export async function loadSettings(): Promise<JsonSetting> {
    if (!settings) {
        const { data } = await axios.get('/src/config/app.setting.json')
        settings = data
    }
    return Promise.resolve(settings ?? defaultJsonSettings)
}

